﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using Entidad;

namespace Persistencia
{
    public class TipoDocumentoDAL
    {
        public List<TipoDocumento> TraerTodos()
        {
            SqlConnection cn = Conexion.Conectar();
            try
            {
                SqlCommand cmd = new SqlCommand("spTipoDocumentoSel", cn);
                cmd.Parameters.Add(new SqlParameter("@Codigo", null));

                cmd.CommandType = CommandType.StoredProcedure;
                SqlDataAdapter da = new SqlDataAdapter(cmd);

                DataSet ds = new DataSet();
                da.Fill(ds, "TipoDocumento");

                /*Creo la lista*/
                List<TipoDocumento> Lista = (from item in ds.Tables[0].AsEnumerable()
                                              select new TipoDocumento()
                                              {
                                                  Codigo = item.Field<int>("Codigo"),
                                                  Nombre = item.Field<string>("Nombre"),

                                              }).ToList();
                return Lista;

            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                cn.Close();
            }
        }
    }
}
